package com.lglbc.democase.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class OrderStrategyHelper {
    private Map<String, OrderStrategy> orderStrategyMap;
    @Autowired
    public void setOrderStrategyMap(List<OrderStrategy> orderStrategyList) {
        if (CollectionUtils.isEmpty(orderStrategyList)) {
            throw new RuntimeException("没找到订单策略");
        }
        orderStrategyMap = orderStrategyList.stream().collect(Collectors.toMap(item -> item.getType(), item -> item, (v1, v2) -> v1));
    }

    public OrderStrategy getHandler(String type){
        return orderStrategyMap.get(type);
    }
    @Autowired
    private OrderStrategyHelper orderStrategyHelper;
    public static void main(String[] args) {
    }
}
